|
|
|
|
|
|
|
Figure 2.7.
The Color dialog box
allows users to select a
color visually, and
returns a numeric
value to the program. |
|
|
|
|
|
|
|
|
Setting up the Common Dialog control to work with colors requires you to set only the Flags property. The Color dialog box returns only one color at a time, requiring you to call the dialog box for every separate color that you want to be able to change. For example, add one additional command button to the existing frmDialog form, and set the Name property to cmdColor and the Caption to Change Color. Then add the following code to the form. The only flag used in this routine tells the Common Dialog control to set the initial color. |
|
|
|
|
|
|
|
|
Private Sub cmdColor_Click()
dlgFileSelect.Flags = cdlCCRGBInit
dlgFileSelect.ShowColor
frmDialog.BackColor = dlgFileSelect.Color
End Sub |
|
|
|
|
|
|
|
|
As you can see, this code changes only the form's background color. When you run the application and change the color, you'll see that the background color of the labels don't change. That's because the code didn't assign the new color to the label's background property. |
|
|
|
|
|
|
|
|
What you've just tried is the basic example of the Color dialog box that every book example uses. Now let's create a separate form that will give users a choice of objects where they can change the color. Create a new form and name it frmColor. This form will allow users to change the colors of the main form background color and the file name text box background color. To do this, use several sets of labels and command buttons, as shown in Figure 2.8. |
|
|
|
|
|